package com.auxgroup.hr.front.service.hireperson.impl;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.dao.domain.PsCHireLanT;
import com.auxgroup.hr.front.dao.domain.PsCHirePrimaryClass;
import com.auxgroup.hr.front.dao.repository.PsCHireLanTRepository;
import com.auxgroup.hr.front.service.hireperson.HireLanService;

/** 
 * @author lvliuhao
 * @version 创建时间：180523 
 * 入职人员语言能力service
 */
@Service("hireLanService")
public class HireLanServiceImpl implements HireLanService {
	private static final Logger logger = LoggerFactory.getLogger(HireEducatServiceImpl.class);
	
	@Autowired
	private PsCHireLanTRepository PsCHireLanTRepository;


	@Override
	public PsCHireLanT getHireLan(PsCHirePrimaryClass hirePrimary) {
		return PsCHireLanTRepository.findOne(hirePrimary);
	}


	@Override
	public PsCHireLanT save(PsCHireLanT HireLan) {
		if(HireLan.getcSeqno()==null){
			HireLan.setHrsRowAddOprid(HireLan.getRsHireId());
			HireLan.setHrsRowAddDttm(new Timestamp(System.currentTimeMillis()));
		}
		HireLan.setHrsRowUpdOprid(HireLan.getRsHireId());
		HireLan.setHrsRowUpdDttm(new Timestamp(System.currentTimeMillis()));
		Set<String> ignoreFields = new HashSet<String>(Arrays.asList("cSeqno"));
		ObjectFieldUtils.handleNullValue(HireLan, ignoreFields);
		return PsCHireLanTRepository.save(HireLan);
	}


	@Override
	public Boolean delete(PsCHirePrimaryClass hirePrimary) {
		try {
			PsCHireLanTRepository.delete(hirePrimary);
		} catch (Exception e) {
			logger.error("delete HireLan error: hirePrimary={}",hirePrimary,e);
			return false;
		}
		return true;
	}
	
	
	@Override
	public List<PsCHireLanT> getAll(String rsHireId) {
		PsCHireLanT HireLan = new PsCHireLanT();
		HireLan.setRsHireId(rsHireId);
		return PsCHireLanTRepository.findAll(Example.of(HireLan));
	}


	
	
	
}
